package com.cy.pj.brand.service.impl;

import com.cy.pj.brand.dao.BrandDao;
import com.cy.pj.brand.pojo.Brand;
import com.cy.pj.brand.service.BrandService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class BrandServiceImpl implements BrandService {

  //  private static final Logger log =
  //                              LoggerFactory.getLogger(BrandServiceImpl.class);

    @Autowired
    private BrandDao brandDao;

    @Override
    public int updateBrand(Brand brand) {

        return brandDao.updateBrand(brand);
    }

    @Override
    public Brand findById(Integer id) {
        Brand brand = brandDao.findById(id);
        return brand;
    }

    @Override
    public int saveBrand(Brand brand) {
        int save = brandDao.saveBrand(brand);
        return save;
    }

    /*
    * 删除业务：
    * 1）权限控制--有权限才可以删除
    * 2）事务控制
    * 3）日志记录
    * 4）。。。。
    * */
    @Override
    public int deleteById(Integer id) {
        int rows = brandDao.deleteById(id);
        return rows;
    }

    @Override
    public List<Brand> findBrands(String name) {
        log.info("start:{}", System.currentTimeMillis());
        List<Brand> list = brandDao.findBrands(name);
        log.info("end:{}",System.currentTimeMillis());
        return list;
    }

}
